<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="../template/layout.xhtml">

	<ui:define name="content">
		<div>
			<br />
			<h:form id="formList" prependId="false">
			
				<p:panelGrid columns="2">  
				    <f:facet name="header"> 
				    	<div align="right">
					      	<p:commandLink value="Nova Cidade" process="@this" actionListener="#{cidadeMB.novaCidade}" 
					        			   oncomplete="modalForm.show();" update=":idForm" style="margin:0"/> 
				    	</div>
				    </f:facet>  
				</p:panelGrid>
			
				<p:dataTable id="dataTable" var="cidade" value="#{cidadeMB.cidades}" styleClass="width100">
					<p:column headerText="#{msg.id}">
						<h:outputText value="#{cidade.id}" />
					</p:column>
					<p:column headerText="#{msg.nome}">
						<h:outputText value="#{cidade.nome}" />
					</p:column>
					<p:column headerText="#{msg.estado}">
						<h:outputText value="#{cidade.estado.nome}" />
					</p:column>
					<p:column>
						<p:commandButton value="#{msg.editar}" update=":idForm" oncomplete="modalForm.show()"> 
							 <f:setPropertyActionListener value="#{cidade}" target="#{cidadeMB.cidade}" />
						</p:commandButton>
					</p:column>
					<p:column>
						<p:commandButton value="#{msg.excluir}" id="excluir" action="#{cidadeMB.excluir}" ajax="false">
							<f:setPropertyActionListener value="#{cidade}" target="#{cidadeMB.cidade}" />
						</p:commandButton>
					</p:column>
				</p:dataTable>
			</h:form>
		</div>
	</ui:define>
	
	<ui:define name="moreComponents">
		<p:dialog id="idModalForm" header="Cadastro de Cidade" widgetVar="modalForm" height="400" width="800" modal="true">  
			<h:form id="idForm" prependId="false">
				<p:tabView activeIndex="0">
        			<p:tab title="Dados Cidade">
        				<ui:include src="/pages/includes/tabCidade.xhtml" />
        			</p:tab>
        		</p:tabView>
				<div align="right">
					<br />
					<p:commandButton id="saveButton" 
									 value="#{msg.button_save}" 
								     actionListener="#{cidadeMB.salvar}" 
									 update=":formList:dataTable" style="margin:0"/>
			        <p:spacer width="5"></p:spacer>
			        <p:commandButton value="#{msg.button_cancel}" onclick="modalForm.hide();" style="margin:0"/> 
				</div>
				<p:messages id="messages" autoUpdate="true" /> 
			</h:form>
		</p:dialog>
	</ui:define>
	
</ui:composition>
</html>